package com.rc.saas.tenant.service.hlht;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.mapper.elec.ElecPileMapper;
import com.rc.saas.tenant.mapper.hlht.HlhtTenantOpenPileMapper;
import com.rc.saas.tenant.model.elec.ElecPile;
import com.rc.saas.tenant.model.hlht.HlhtTenantOpen;
import com.rc.saas.tenant.search.hlht.HlhtTenantOpenPileSearch;
import com.rc.saas.tenant.vo.hlht.HlhtTenantOpenPileVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wangzhengwei
 * @create 2021/8/12
 */
@Service
public class HlhtTenantOpenPileServiceImpl implements HlhtTenantOpenPileService {

    @Autowired
    private HlhtTenantOpenPileMapper hlhtTenantOpenPileMapper;

    @Autowired
    private ElecPileMapper elecPileMapper;

    @Override
    public HlhtTenantOpenPileMapper getMapper() {
        return hlhtTenantOpenPileMapper;
    }

    @Override
    public void insertBatchByElecPileList(HlhtTenantOpen hlhtTenantOpen, List<ElecPile> elecPileList,String hlhtOpenforType, String loginName) {
        //先删除旧依赖关系
        hlhtTenantOpenPileMapper.deleteBatchByElecPileList(hlhtTenantOpen,elecPileList,hlhtOpenforType);
        //新增新依赖关系
        hlhtTenantOpenPileMapper.insertBatchByElecPileList(hlhtTenantOpen, elecPileList,hlhtOpenforType, loginName);
    }

    @Override
    public void deleteBatchByElecStationIdList(HlhtTenantOpen hlhtTenantOpen, List<Long> elecStationIdList) {
        hlhtTenantOpenPileMapper.deleteBatchByElecStationIdList(hlhtTenantOpen, elecStationIdList);
    }

    @Override
    public void updatePileHlhtOpenforTypeBatchByOpenStationIdList(HlhtTenantOpen hlhtTenantOpen, List<Long> openedStationIdList, String hlhtOpenforType) {
        hlhtTenantOpenPileMapper.updatePileHlhtOpenforTypeBatchByOpenStationIdList(hlhtTenantOpen, openedStationIdList, hlhtOpenforType);
    }

    @Override
    public PageInfo<HlhtTenantOpenPileVo> listPageHlhtTenantOpenPile(HlhtTenantOpenPileSearch hlhtTenantOpenPileSearch) {
        PageHelper.startPage(hlhtTenantOpenPileSearch.getOffset(), hlhtTenantOpenPileSearch.getLimit());
        List<HlhtTenantOpenPileVo> hlhtTenantOpenPileVoList = elecPileMapper.listPageHlhtTenantOpenPile(hlhtTenantOpenPileSearch);
        return new PageInfo<>(hlhtTenantOpenPileVoList);
    }

    @Override
    public List<Long> getElecPileIdByOpenPile(List<Long> openPileIdList) {
        return hlhtTenantOpenPileMapper.getElecPileIdByOpenPile(openPileIdList);
    }

    @Override
    public void deleteByBatch(List<Long> openPileIdList) {
        hlhtTenantOpenPileMapper.deleteByBatch(openPileIdList);
    }

    @Override
    public void updateHlhtOpenforTypeBatchByOpenPileIdList(List<Long> openPileIdList, String hlhtOpenforType) {
        hlhtTenantOpenPileMapper.updateHlhtOpenforTypeBatchByOpenPileIdList(openPileIdList, hlhtOpenforType);
    }

}
